home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / program / bgui12.lha / demos / idcmphook.c < prev    next >
C/C++ Source or Header  |  1995-04-23  |  6KB  |  153 lines

  1. ;/* Execute me to compile with DICE V3.0
  2. dcc idcmphook.c -proto -mi -ms -mRR -lbgui
  3. quit
  4. */
  5. /*
  6. **      IDCMPHOOK.C
  7. **
  8. **      (C) Copyright 1995 Jaba Development.
  9. **      (C) Copyright 1995 Jan van den Baard.
  10. **          All Rights Reserved.
  11. **/
  12.  
  13. #include "democode.h"
  14.  
  15. /*
  16. **      Object ID.
  17. **/
  18. #define ID_QUIT                 1
  19.  
  20. /*
  21. **      "tick" counter for the hook.
  22. **/
  23. UBYTE   Ticks = 0;
  24.  
  25. /*
  26. **      Simple example of the hook code.
  27. **/
  28. SAVEDS ASM VOID hookFunc( REG(a0) struct Hook *hook, REG(a2) Object *obj, REG(a1) struct IntuiMessage *imsg )
  29. {
  30.         struct Window                   *wptr = NULL;
  31.  
  32.         /*
  33.         **      This hook is a simple IDCMP_INTUITICKS hook.
  34.         **      More complex hooks can receive several message
  35.         **      types depending on the setting of the
  36.         **      WINDOW_IDCMPHookBits attribute.
  37.         **
  38.         **      Simply beep the screen
  39.         **      every two seconds or so
  40.         **      while the window is active.
  41.         **/
  42.         if ( Ticks == 20 ) {
  43.                 Ticks = 0;
  44.                 /*
  45.                 **      Only flash the screen on which
  46.                 **      the window is located.
  47.                 **/
  48.                 GetAttr( WINDOW_Window, obj, ( ULONG * )&wptr );
  49.                 if ( wptr )
  50.                         DisplayBeep( wptr->WScreen );
  51.         }
  52.         Ticks++;
  53. }
  54.  
  55.  
  56. /*
  57. **      The hook structure.
  58. **
  59. ** typedef unsigned long (*HOOKFUNC)();
  60. **/
  61. struct Hook idcmpHook = { NULL, NULL, (HOOKFUNC)hookFunc, NULL, NULL };
  62.  
  63. VOID StartDemo( void )
  64. {
  65.         struct Window           *window;
  66.         Object                  *WO_Window, *GO_Quit;
  67.         ULONG                    signal = 0, rc, tmp = 0;
  68.         BOOL                     running = TRUE;
  69.  
  70.         /*
  71.         **      Create the window object.
  72.         **/
  73.         WO_Window = WindowObject,
  74.                 WINDOW_Title,           "IDCMPHook Demo",
  75.                 WINDOW_SizeGadget,      FALSE,
  76.                 WINDOW_RMBTrap,         TRUE,
  77.                 WINDOW_IDCMP,           IDCMP_INTUITICKS,
  78.                 WINDOW_IDCMPHookBits,   IDCMP_INTUITICKS,
  79.                 WINDOW_IDCMPHook,       &idcmpHook,
  80.                 WINDOW_AutoAspect,      TRUE,
  81.                 WINDOW_MasterGroup,
  82.                         /*
  83.                         **      A simple vertical group
  84.                         **      containing a descriptive text
  85.                         **      and a "Quit" button.
  86.                         **/
  87.                         VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ), GROUP_BackFill, SHINE_RASTER,
  88.                                 StartMember, InfoFixed( NULL, "\33cThis small demo has a IDCMP-hook\n"
  89.                                                               "installed which will flash the\n"
  90.                                                               "display every two seconds while the\n"
  91.                                                               "window is active.", NULL, 4 ), EndMember,
  92.                                 StartMember,
  93.                                         HGroupObject,
  94.                                                 VarSpace( DEFAULT_WEIGHT ),
  95.                                                 StartMember, GO_Quit  = KeyButton( "_Quit",  ID_QUIT  ), EndMember,
  96.                                                 VarSpace( DEFAULT_WEIGHT ),
  97.                                         EndObject,
  98.                                 EndMember,
  99.                         EndObject,
  100.         EndObject;
  101.  
  102.         /*
  103.         **      Object created OK?
  104.         **/
  105.         if ( WO_Window ) {
  106.                 /*
  107.                 **      Assign a key to the button.
  108.                 **/
  109.                 if ( GadgetKey( WO_Window, GO_Quit,  "q" )) {
  110.                         /*
  111.                         **      try to open the window.
  112.                         **/
  113.                         if ( window = WindowOpen( WO_Window )) {
  114.                                 /*
  115.                                 **      Obtain it's wait mask.
  116.                                 **/
  117.                                 GetAttr( WINDOW_SigMask, WO_Window, &signal );
  118.                                 /*
  119.                                 **      Event loop...
  120.                                 **/
  121.                                 do {
  122.                                         Wait( signal );
  123.                                         /*
  124.                                         **      Handle events.
  125.                                         **/
  126.                                         while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE ) {
  127.                                                 /*
  128.                                                 **      Evaluate return code.
  129.                                                 **/
  130.                                                 switch ( rc ) {
  131.  
  132.                                                         case    WMHI_CLOSEWINDOW:
  133.                                                         case    ID_QUIT:
  134.                                                                 running = FALSE;
  135.                                                                 break;
  136.                                                 }
  137.                                         }
  138.                                 } while ( running );
  139.                         } else
  140.                                 Tell( "Could not open the window\n" );
  141.                 } else
  142.                         Tell( "Could not assign gadget key\n" );
  143.                 /*
  144.                 **      Disposing of the window object will
  145.                 **      also close the window if it is
  146.                 **      already opened and it will dispose of
  147.                 **      all objects attached to it.
  148.                 **/
  149.                 DisposeObject( WO_Window );
  150.         } else
  151.                 Tell( "Unable to create the window object\n" );
  152. }
  153.